package com.lottery.ruok.lottrey.activity;

import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.widget.TextView;
import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.retrofitModule.RetrofitBase;
import com.lottery.ruok.lottrey.retrofitModule.RxHelper;
import com.lottery.ruok.lottrey.retrofitModule.RxSubscribe;
import com.lottery.ruok.lottrey.retrofitModule.request.GetHasSMSRequest;
import com.lottery.ruok.lottrey.retrofitModule.response.GetHasSMSResponse;
import butterknife.BindView;
import butterknife.ButterKnife;

/*
* 开户协议
* */

public class OpenAccountProtocolActivity extends BaseActivity {

    @BindView(R.id.webview)
    TextView webview;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_open_protocol);
        ButterKnife.bind(this);

        init();
    }

    private void init() {
        RetrofitBase.getRetrofit().create(GetHasSMSRequest.class).getResult("site_agreement")
                .compose(RxHelper.<GetHasSMSResponse>handleResult())
                .subscribe(new RxSubscribe<GetHasSMSResponse>(this) {
                    @Override
                    protected void _onNext(GetHasSMSResponse getHasSMSResponse) {
                        if(webview != null && getHasSMSResponse != null && getHasSMSResponse.getValue() != null) {
                            webview.setText(getHasSMSResponse.getValue().getAsJsonObject().get("context").getAsString());
                            webview.setMovementMethod(new ScrollingMovementMethod());
                        }
                    }

                    @Override
                    protected boolean showDialog() {
                        return false;
                    }
                });
    }
}